@extends('layouts.app')
@include('system.sidebar')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <a class="btn btn-success add-attr" href="{{route('admin.system.rule.create')}}">添加产品类别</a>
            <br />
            <br />
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>图片</th>
                    <th>操作</th>
                    <th>排序权重</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>
                            <img src = "{{ \App\Library\OSS::instance()->getUrl($item->image) }}" width="300">
                        </td>
                        <td>
                            <a class="btn btn-primary btn-xs" href="{{ route('admin.system.rule.edit', ['id' => $item->id]) }}"><i class="fa fa-edit"></i> 编辑</a>
                            <a class="btn btn-primary btn-xs delete-confirm" data-href="{{ route('admin.system.rule.delete', ['id' => $item->id]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                        </td>
                        <td>
                            <input type="text" class="col-xs-3 change-sort" data-id="{{ $item->id }}" value="{{ $item->sort }}" />
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.system.rule.sort') }}',
                type: "GET",
                dataType:'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });
    </script>
@endpush
